<?php
require_once 'vendor/autoload.php';

use think\facade\Db;

// 初始化应用
$app = new \think\App();
$app->initialize();

echo "开始测试配置保存功能...\n";

// 模拟前端发送的数据
$testData = [
    'xiaofeng_order_token' => 'shop-7c71e001e677a0b33c0b5c07a1b0d9ed',
    'xiaofeng_create_order_token' => 'afba91441e1b710fda8f01f4bac77a01'
];

echo "测试数据: " . json_encode($testData, JSON_UNESCAPED_UNICODE) . "\n\n";

// 测试 SystemConfig::batchUpdate 方法
try {
    $success = \app\model\SystemConfig::batchUpdate($testData);
    echo "batchUpdate 结果: " . ($success ? '成功' : '失败') . "\n";
    
    if ($success) {
        // 验证数据是否保存成功
        $orderToken = \app\model\SystemConfig::getConfig('xiaofeng_order_token');
        $createOrderToken = \app\model\SystemConfig::getConfig('xiaofeng_create_order_token');
        
        echo "验证保存结果:\n";
        echo "xiaofeng_order_token: " . ($orderToken ?: '未找到') . "\n";
        echo "xiaofeng_create_order_token: " . ($createOrderToken ?: '未找到') . "\n";
    }
} catch (Exception $e) {
    echo "错误: " . $e->getMessage() . "\n";
}

echo "\n测试完成！\n"; 